﻿namespace PorteringManagement.Web
{
    using System.Collections.Generic;
    using System.Data.Entity;
    using PorteringManagement.Model;

    public class PorteringManagementDataInitializer : DropCreateDatabaseIfModelChanges<PorteringManagementContext>
    {
        protected override void Seed(PorteringManagementContext context)
        {
            var ports = new List<Port>
            {
                new Port { PortID = 1, Name = "Puerto 1", Capacity = 15 },
                new Port { PortID = 2, Name = "Puerto 2", Capacity = 25 },
                new Port { PortID = 3, Name = "Puerto 3", Capacity = 45 }
            };

            var portRelations = new List<PortRelation>
            {
                new PortRelation { PortRelationID = 1, OriginPortID = ports[0].PortID, OriginPort = ports[0], DestinationPortID = ports[1].PortID, DestinationPort = ports[1], TimeWeight = 7, WeatherWeight = 25, CostWeight = 25 },
                new PortRelation { PortRelationID = 2, OriginPortID = ports[1].PortID, OriginPort = ports[1], DestinationPortID = ports[0].PortID, DestinationPort = ports[0], TimeWeight = 7, WeatherWeight = 25, CostWeight = 25 },
                new PortRelation { PortRelationID = 3, OriginPortID = ports[0].PortID, OriginPort = ports[0], DestinationPortID = ports[2].PortID, DestinationPort = ports[2], TimeWeight = 3, WeatherWeight = 9, CostWeight = 12 },
                new PortRelation { PortRelationID = 4, OriginPortID = ports[2].PortID, OriginPort = ports[2], DestinationPortID = ports[0].PortID, DestinationPort = ports[0], TimeWeight = 3, WeatherWeight = 9, CostWeight = 12 },
                new PortRelation { PortRelationID = 5, OriginPortID = ports[1].PortID, OriginPort = ports[1], DestinationPortID = ports[2].PortID, DestinationPort = ports[2], TimeWeight = 6, WeatherWeight = 10, CostWeight = 11 },
                new PortRelation { PortRelationID = 6, OriginPortID = ports[2].PortID, OriginPort = ports[2], DestinationPortID = ports[1].PortID, DestinationPort = ports[1], TimeWeight = 6, WeatherWeight = 10, CostWeight = 11 }
            };

            var customers = new List<Customer>
            {
                new Customer { CustomerID = 1, Name = "Cliente 1", Email = "cliente1@contoso.com" },
                new Customer { CustomerID = 2, Name = "Cliente 2", Email = "cliente2@contoso.com" }
            };

            var cargoTypes = new List<CargoType>
            {
                new CargoType { CargoTypeID = 1, Name = "Estandar" },
                new CargoType { CargoTypeID = 2, Name = "Aislada" },
                new CargoType { CargoTypeID = 3, Name = "Refrigerada" }
            };

            ports.ForEach(p => context.Ports.Add(p));
            portRelations.ForEach(p => context.PortRelations.Add(p));
            customers.ForEach(c => context.Customers.Add(c));
            cargoTypes.ForEach(ct => context.CargoTypes.Add(ct));
        } 
    }
}